import {
  exportUrl,
  downloadTemplateUrl,
  getOrderStatusList,
  getOperationStatusList,
} from '@/api/materialRequisition/mesRequisitionOrder'

import { exportExcel } from '@/utils/judge'

// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t('common.export'),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl,
    //auth: "auth:operlog:export", //权限字段
  },
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    icon: "el-icon-edit-outline",
    handleName: "edit", //点击时返回的标识
    isMultiple: true, //至少选择一条
    auth: "auth:mesRequisitionOrder:edit", //权限字段
    //是否可点击；
    disabled: (data) => {
      let len = data.filter(ite => ite.sourceType == 'MES');
      return !(data.length >= 1)&&!(len==data.length);
    },
  },
  {
    name: $i18n.t("mesMaterialRequisition.close"),
    type: "danger",
    icon: "el-icon-document-delete",
    handleName: "closeOrder", //点击时返回的标识
    auth: "auth:mesRequisitionOrder:close", //权限字段
    isMultiple: true, // isSingle 表示必须选择一项//isMultiple: true, // 表示必须多选
    //是否可点击；
    disabled: (data) => {
      let len = data.filter(ite => ite.sourceType == 'MES');
      return !(data.length >= 1)&&!(len==data.length);
    },
  },
  // {
  //   name: $i18n.t("common.import"),
  //   type: "primary",
  //   icon: "el-icon-circle-plus-outline",
  //   handleName: "import", //点击时返回的标识
  // },
]
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
]
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    orderNo: {
      type: 'input',
      label: $i18n.t('mesRequisitionOrder.orderNo'),  // 生产订单编码
    },
    planCode: {
      type: 'input',
      label: $i18n.t('mesRequisitionOrder.planCode'),  // 生产订单编码
    },
    orderStatus: {
      type: 'select',
      label: $i18n.t('mesRequisitionOrder.orderStatus'),  // 状态 0创建1领料中2已完成3已关闭
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getOrderStatusList()
        return list.data.result
      },
    },
    planTime: {
      type: 'datetimerange',
      label: $i18n.t('mesRequisitionOrder.planTime'),  // 计划时间
      attrs: {
        valueFormat: "yyyy-MM-dd HH:mm:ss",
        searchArrKey: ["planTimeMin", "planTimeMax"]
      },
    },
  },
}
// 新增/删除表单配置
export const formDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  formDesc: {
    orderNo: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.orderNo"),  // 单据编号
      layout: 12,
      required: true,
    },
    warehouseCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.warehouseCode"),  // 仓库编码
      layout: 12,
      required: true,
    },
    warehouseName: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.warehouseName"),  // 仓库名称
      layout: 12,
      required: true,
    },
    orderStatus: {
      type: "select",
      label: $i18n.t("mesRequisitionOrder.orderStatus"),  // 状态 0创建1领料中2已完成3已关闭
      layout: 12,
      required: true,
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getOrderStatusList()
        return list.data.result
      },
    },
    orderType: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.orderType"),  // 单据类型 10领料出库
      layout: 12,
      required: true,
    },
    planQty: {
      type: "number",
      label: $i18n.t("mesRequisitionOrder.planQty"),  // 计划数量
      layout: 12,
      required: true,
    },
    scanQty: {
      type: "number",
      label: $i18n.t("mesRequisitionOrder.scanQty"),  // 扫描数量
      layout: 12,
      required: true,
    },
    upstreamOrderNo: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.upstreamOrderNo"),  // 上游单据编号
      layout: 12,
      required: false,
    },
    supplyCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.supplyCode"),  // 供应商编码
      layout: 12,
      required: false,
    },
    supplyName: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.supplyName"),  // 供应商名称
      layout: 12,
      required: false,
    },
    customerCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.customerCode"),  // 客户编码
      layout: 12,
      required: false,
    },
    customerName: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.customerName"),  // 客户名称
      layout: 12,
      required: false,
    },
    planTime: {
      type: "datetime",
      label: $i18n.t("mesRequisitionOrder.planTime"),  // 计划时间
      layout: 12,
      required: true,
      attrs: {
        "valueFormat": "yyyy-MM-dd HH:mm:ss",
      },
    },
    planCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.planCode"),  // 生产订单编码
      layout: 12,
      required: true,
    },
    sourceType: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.sourceType"),  // 数据来源 1-mes 2-wms 3-其它
      layout: 12,
      required: true,
    },
    factoryCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.factoryCode"),  // 工厂编码
      layout: 12,
      required: true,
    },
    remark: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.remark"),  // 备注
      layout: 12,
      required: false,
    },
    operationStatus: {
      type: "select",
      label: $i18n.t("mesRequisitionOrder.operationStatus"),  // 操作状态 0-新建，1-修改，2-关闭，3-完成，4-失败
      layout: 12,
      required: false,
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getOperationStatusList()
        return list.data.result
      },
    },
    operationFailReason: {
      type: "input",
      label: $i18n.t("mesRequisitionOrder.operationFailReason"),  // 失败原因
      layout: 12,
      required: false,
    },
  },
}
//导入数据
export const importFormDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  formDesc: {
    model: {
      type: "button",
      label: "",
      layout: 24,
      required: false,
      title: $i18n.t("common.downloadTemplate"), // 下载模板
      style: {
        color: '#1867c0',
        fontSize: '14px'
      },
      on: {
        click: () => {
          exportExcel(downloadTemplateUrl)
        }
      }
    },
    file: {
      type: "input",
      label: $i18n.t("common.chooseFile"),
      layout: 24,
      // required: true,

    },
  }
}

